package cn.seqdata.jpa.converter;

import javax.persistence.AttributeConverter;

import org.joda.time.LocalDate;

public class LocalDateConverter implements AttributeConverter<LocalDate, java.sql.Date> {
	public static final LocalDateConverter instance = new LocalDateConverter();

	@Override
	public java.sql.Date convertToDatabaseColumn(LocalDate attribute) {
		return null != attribute ? new java.sql.Date(attribute.toDateTimeAtStartOfDay()
			.getMillis()) : null;
	}

	@Override
	public LocalDate convertToEntityAttribute(java.sql.Date dbData) {
		return null != dbData ? new LocalDate(dbData.getTime()) : null;
	}
}
